package ophiux.wechatpay.sdk.common.net;

import ophiux.wechatpay.sdk.OphiuxWeChatPaySDKException;
import ophiux.wechatpay.sdk.common.utils.HttpUtil;

public class WebserviceApiRequest implements INetApiRequest {

	@Override
	public String request(String serviceURL, String methodName, String StrParam) 
			throws OphiuxWeChatPaySDKException {
		 return request(serviceURL, methodName, StrParam,30*1000);
	}

	@Override
	public String request(String serviceURL, String methodName, String StrParam,
			int timeOut)throws OphiuxWeChatPaySDKException {
		String response = null;
		try {
			response = HttpUtil.httpsRequest(serviceURL, methodName, StrParam, timeOut);
			response = response.replaceAll("&lt;", "<");
		    response = response.replaceAll("&gt;", ">");
			response = response.replaceAll("<return>", "%");
			response = response.replaceAll("</return>", "%");; 
			response = response.replaceAll("&quot;", "\"");
			String[] body = response.split("%");
			response = body[1];
			response = response.replaceAll("&#xD;", "");
		} catch (Exception e) {
			throw new OphiuxWeChatPaySDKException(e);
		}
		return response;
	}

	@Override
	public String getPostMethodSSL(String serviceURL, String methodName,
			String StrParam, String sslFilePath, String mch_id)
			throws OphiuxWeChatPaySDKException {
		// TODO Auto-generated method stub
		return null;
	}

}
